package net.plentz.tagger.ui.widgets.views;

import net.plentz.tagger.ui.listeners.events.AbstractEvent;
import net.plentz.tagger.ui.listeners.events.AbstractEvent.Action;
import net.plentz.tagger.ui.widgets.GlobalDirectoryWidget;
import net.plentz.tagger.ui.widgets.MusicInfoWidget;
import net.plentz.tagger.ui.widgets.MusicListWidget;
import net.plentz.tagger.ui.widgets.MusicListWidget.Column;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;

public class HomeView extends AbstractView {

	@Override
	public Composite render(Composite parent, int flags) {

		Composite c = new Composite(parent, flags);
		GridData gridData;

		// Layout
		c.setLayout(new GridLayout(2, false));

		// Declare widgets
		GlobalDirectoryWidget globalDirectoryWidget = new GlobalDirectoryWidget();
		MusicListWidget musicListWidget = new MusicListWidget();
		MusicInfoWidget musicInfoWidget = new MusicInfoWidget();

		// Initialize music list widget with default columns
		musicListWidget.setColumns(new Column[] {
				Column.FILENAME, Column.FILESIZE
		});

		// Initialize the global directory widget so it can talk to the music list
		globalDirectoryWidget.addListener(Action.SET_GLOBAL_DIRECTORY, musicListWidget);

		// Initialize the music list so it can talk to the music info panel
		musicListWidget.addListener(Action.SET_MUSIC_DATA, musicInfoWidget);

		// Render widgets
		Composite globalDirectory = globalDirectoryWidget.render(c, SWT.NONE);
		Composite musicList = musicListWidget.render(c, SWT.NONE);
		Composite musicInfo = musicInfoWidget.render(c, SWT.BORDER);

		// Widget layout data
		globalDirectory.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false, 2, 1));
		musicList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

		gridData = new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1);
		// gridData.widthHint = 312;
		musicInfo.setLayoutData(gridData);

		// Initialize default directory
		globalDirectoryWidget.setDirectory(System.getProperty("user.home"));

		musicList.pack();
		c.pack();

		return c;

	}

	@Override
	protected <T> void invokeEvent(AbstractEvent<T> event) {
		// TODO Auto-generated method stub

	}

}
